
#include "SafeBoxInterface.h"


ISafeBoxInterface::ISafeBoxInterface()
{
	m_refCount = 1;
}

ISafeBoxInterface::~ISafeBoxInterface()
{

}

HRESULT ISafeBoxInterface::QueryInterface(REFIID riid, void** ppvObject) {
	*ppvObject = nullptr;
	if (riid == IID_IUnknown) {
		*ppvObject = this;
	}
	else if (riid == __uuidof(ISafeBoxInterface)) {
		*ppvObject = static_cast<ISafeBoxInterface*>(this);
	}
	if (*ppvObject) {
		AddRef();
		return S_OK;
	}

	return E_NOINTERFACE;
}

ULONG ISafeBoxInterface::AddRef() {
	return InterlockedIncrement(&m_refCount);
}

ULONG ISafeBoxInterface::Release() {
	ULONG refCount = InterlockedDecrement(&m_refCount);
	if (refCount == 0) {
		delete this;
	}
	return refCount;
}

void ISafeBoxInterface::SetManager()
{
	gHostProcess.dwPorcessFlags |= HP_MANAGER_PROCESS;
}

void ISafeBoxInterface::SetLpcPort(ULONG uLpcPort)
{
	gBoxInfo.uLpcPort = uLpcPort;
}

ULONG ISafeBoxInterface::SetEnvironment(PSAFEBOX_INFO pBoxInfo)
{
	return ::SetSafeBoxInfo(pBoxInfo);
}

